package com.sun.showcase.controller.app.mall;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.aliyuncs.utils.StringUtils;
import com.sun.showcase.biz.mall.service.CommentService;
import com.sun.showcase.client.domain.mall.Comment;
import com.sun.showcase.client.query.mall.CommentQuery;
import com.sun.showcase.pojo.DataGrid;
import com.sun.showcase.pojo.Result;
import com.sun.showcase.utils.ExecuteResult;
@CrossOrigin
@RestController("appCommentController")
@RequestMapping(value="/app/comment") 
public class CommentController{
	
	@Autowired
	private CommentService commentService;
	
	private Result result = new Result();

	@RequestMapping(value="save")
	public Result save(CommentQuery commentQuery) {
		ExecuteResult<Comment> exe = commentService.save(commentQuery);
		if(exe.isSuccess()) {
			result.setSuccess(true);
		}else {
			result.setSuccess(false);
			result.setMsg(exe.getErrorMessages().get(0));
		}
		return result;
	}
	
	@RequestMapping(value="list")
	public Result list(CommentQuery commentQuery) {
		if(StringUtils.isEmpty(commentQuery.getGoodsId())) {
			result.setSuccess(false);
			result.setMsg("无效查询！");
			return result;
		}
		commentQuery.setShowStatus("1");
		DataGrid dg = commentService.datagrid(commentQuery);
		result.setSuccess(true);
		result.setData(dg);
		return result;
	}
}
